<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        //11. 封装计算两个日期之间差值的函数
        // - 利用参数，传入两个指定日期（字符）
        // - 返回值为对象，如：{day:x, hour: y, minu: z, sec: s}
        
        var time1 = new Date('2020-02-28 0:02:23') 
        var time2 = new Date('2022-02-23 02:02:50')
        var timet1 = '2020-02-28 0:0'
        var timet2 = '2022-02-23 0:0:2'
        // console.log(time1.getTime()) 
        // console.log(time2.getTime()) 
        function rqc(timet1,timet2){
            timet1=new Date(timet1)
            timet1=timet1.getTime()
            timet2=new Date(timet2)
            timet2=timet2.getTime()
            return {
                day:Math.abs((timet1-timet2)/1000/60/60/24)+'天',
                hour:Math.abs((timet1-timet2)/1000/60/60)+'时',
                minu:Math.abs((timet1-timet2)/1000/60)+'分',
                sec:Math.abs((timet1-timet2)/1000)+'秒',
            }
        }
        console.log(rqc(timet1,timet2))
        // console.log(time1.getTime()) 
        // console.log(time1.getTime()) 
        /* var sto
        sto=setTimeout(aaa,5000)
        function aaa(){
            console.log(time1.getTime()) 
        }
        console.log(time2)  */
        // console.log(rqc(time1,time2))
    </script>
</body>
</html>